import CryptoJS from 'crypto-js';

// key 值
const keyWord = 'amazone-commerce';
// 边偏移
const iv = '';

export default class ECB {
  // 加密
  static encrypt(word) {
    let key = CryptoJS.enc.Utf8.parse(keyWord);
    let iv = CryptoJS.enc.Utf8.parse(iv);
    let srcs = CryptoJS.enc.Utf8.parse(word);

    let encrypted = CryptoJS.AES.encrypt(srcs, key, {
      iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.ZeroPadding,
    });
    return encrypted.toString();
  }

  // 解密事件
  static decrypt(word) {
    var key = CryptoJS.enc.Utf8.parse(keyWord);
    let iv = CryptoJS.enc.Utf8.parse(iv);

    var decrypt = CryptoJS.AES.decrypt(word, key, {
      iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.ZeroPadding,
    });
    return decrypt.toString(CryptoJS.enc.Utf8);
  }
}
